<?
require_once("cls_db.php");

class cls_product
{		
	function get_product($brand_id)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_product WHERE coordinator_id = ".$brand_id;

		$result	= $db->get_all_data($sql);
		
		$db->db_close();
		
		return $result;
	}//get_tour_detail
	
	function getnewproduct($brand_id)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_product WHERE status='new'";
	

		$result	= $db->get_all_data($sql);
		
		$db->db_close();
		
		return $result;
	}//get_tour_detail
	

	
	function delete_product($id)
	{
		$db		= new db();
		
		$sql = "Delete from tbl_product where product_id = $id";
			
		return $db->execute_nonquery($sql);
		
		
		
		
	}
	
	function get_brand_list()
	{
		$db = new db();
		$sql	= "SELECT * FROM tbl_coordinator where status ='1'";

		return $db->get_all_data($sql);
	}
	
	function get_type_list()
	{
		$db = new db();
		$sql	= "SELECT DISTINCT type FROM tbl_product";

		return $db->get_all_data($sql);
	}
	
	function get_product_search($arr)
	{
		$db = new db();
		$sql	= "SELECT * FROM tbl_product ".
					" WHERE brand = '{$arr['brand']}'";
		
		if (strlen(trim($arr['type'])))
			$sql .= " AND type LIKE '%{$arr['type']}%'";
			
		
		$sql .= " ORDER BY brand";
		
		//echo  $sql;
		
		return $db->get_all_data($sql);
	}
	
	
	function get_product_by_brand($brand)
	{
		$db = new db();
		$sql	= "SELECT * FROM tbl_product WHERE coordinator_id = '$brand' ORDER BY brand";

		return $db->get_all_data($sql);
		
	}//get_product_by_brand
	
	
	function show_product($id)
	{
		$db		= new db();
		
		$sql	= "SELECT * FROM tbl_product where product_id = $id";		
		
		return $db->get_all_data($sql);
		
	}
	
	function edit_product($arr)
	{
		$db		= new db();
		
		$sql	=   "UPDATE tbl_product SET ".
					"brand='".$arr['brand']."', ".
					"type='".$arr['type']."', ".
					"price='".$arr['price']."' ".
					" WHERE product_id =".  $arr['product_id'];	
		
		return $db->execute_nonquery($sql);
		
	}
	
	function insert_product($arr)
	{
		$db 	= new db();
		$sql	= "INSERT INTO tbl_product (coordinator_id,brand,price,status)".
					"VALUES ('".$arr['coordinator_id']."','".
					$arr['brand']."','".
					 
					(int)$arr['price'].",".
					"'".$arr['status']."')";
				
					//echo $sql;
		$db->execute_nonquery($sql);
		
		return mysql_insert_id();
	}//insert_tour
	
	function insert_new_product($arr)
	{
		$db 	= new db();
		$sql	= "INSERT INTO tbl_product (coordinator_id,brand,price,status)".
					"VALUES ('".$arr['coordinator_id']."','".
					$arr['brand']."',".
					 
					(int)$arr['price'].",".
					"'".$arr['status']."')";
				
		$db->execute_query($sql);
		
		return mysql_insert_id();
	}//insert_tour

	
	function get_product_by_product_id($id)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_product WHERE product_id = ".$id;

		$result	= $db->get_all_data($sql);
		
		$db->db_close();
		
		return $result;
	}//get_tour_detail
	
	function get_product_list($pageno = 1)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_coordinator c, tbl_product p ".
					"WHERE c.coordinator_id = p.coordinator_id ORDER BY p.product_id";
		//echo $sql;
		$db->set_pageno($pageno);
		$result = $db->get_datalist($sql);

		$result['pagecount']	= $db->get_pagecount();
		
		$result['numrows']		= $db->get_numrows($sql);
		
		$db->db_close();
		
		return $result;

		//$row = $db->get_all_data($sql);

		//if (count($row)) {
			//return $row;
		//}
	}//get_user
	
	function delete_product_list($id)
	{
		$db		= new db();
		
		$sql = "Delete from tbl_product where product_id = $id";
			
		return $db->execute_nonquery($sql);
		
	
		
	}
	
	
	function gettypename($id){
		$db		= new db();
		
		$sql = "select coordinator_name from tbl_coordinator where coordinator_id = $id";
			
		$row = $db->execute_query($sql);
		return $row['coordinator_name'];
		 
	}
	
	function getproductall(){
		$db		= new db();
		
		$sql = "select * from tbl_product";
			return $db->get_all_data($sql);
		 
	}
}//class	

?>